package com.ruoyi.project.countrybus.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.countrybus.domain.SysDispatchCustomer;
import com.ruoyi.project.countrybus.service.ISysDispatchCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 乘客调度站点Controller
 * 
 * @author yangwenbo
 * @date 2022-04-24
 */
@RestController
@RequestMapping("/countrybus/schedule")
public class SysDispatchCustomerController extends BaseController
{
    @Autowired
    private ISysDispatchCustomerService sysDispatchCustomerService;

    /**
     * 查询乘客调度站点列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDispatchCustomer sysDispatchCustomer)
    {
        startPage();
        List<SysDispatchCustomer> list = sysDispatchCustomerService.selectSysDispatchCustomerList(sysDispatchCustomer);
        return getDataTable(list);
    }

    /**
     * 导出乘客调度站点列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:export')")
    @Log(title = "乘客调度站点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDispatchCustomer sysDispatchCustomer)
    {
        List<SysDispatchCustomer> list = sysDispatchCustomerService.selectSysDispatchCustomerList(sysDispatchCustomer);
        ExcelUtil<SysDispatchCustomer> util = new ExcelUtil<SysDispatchCustomer>(SysDispatchCustomer.class);
        util.exportExcel(response, list, "乘客调度站点数据");
    }

    /**
     * 获取乘客调度站点详细信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return AjaxResult.success(sysDispatchCustomerService.selectSysDispatchCustomerByScheduleId(scheduleId));
    }

    /**
     * 新增乘客调度站点
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:add')")
    @Log(title = "乘客调度站点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDispatchCustomer sysDispatchCustomer)
    {
        return toAjax(sysDispatchCustomerService.insertSysDispatchCustomer(sysDispatchCustomer));
    }

    /**
     * 修改乘客调度站点
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:edit')")
    @Log(title = "乘客调度站点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDispatchCustomer sysDispatchCustomer)
    {
        return toAjax(sysDispatchCustomerService.updateSysDispatchCustomer(sysDispatchCustomer));
    }

    /**
     * 删除乘客调度站点
     */
    @PreAuthorize("@ss.hasPermi('countrybus:schedule:remove')")
    @Log(title = "乘客调度站点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(sysDispatchCustomerService.deleteSysDispatchCustomerByScheduleIds(scheduleIds));
    }
}
